/**
 * Created by wang on 2017/4/5.
 */
$(function(){
 function  DateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式  
       var  aDate,  oDate1,  oDate2,  iDays  ;
       aDate  =  sDate1.split("-")  ;
       oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);    //转换为12-18-2006格式  
       aDate  =  sDate2.split("-")  ;
       oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]) ; 
       iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)  ;  //把相差的毫秒数转换为天数  
       return  iDays  ;
}    
function DASearch(){

    function getFromTo() {
        var fromTo=$('#date_demo3').text();   
        fromTo=fromTo.replace(/\s*/g,'').split('至');
        return fromTo;
    }
	var from = getFromTo()[0];
	var to = getFromTo()[1];
	var l = DateDiff(from,to);
	
	
    var aryjsyl = new Array();//进水压力
    var arychyl = new Array();//出水压力
    var ary1 = new Array();//1#
    var ary2 = new Array();//2#

    	
    for (var i = 0 ;i<l;i++) {
    	var a = "0.3"+Math.floor(Math.random()*10+1);
		var b = "0.7"+Math.floor(Math.random()*10+1);
		var c = Math.random()+2;
		var d = Math.random()+1.5;
		aryjsyl.push(a);
		arychyl.push(b);
		ary1.push(c.toFixed(1));
		ary2.push(d.toFixed(1));
    }

   	  var option = myChart10.getOption();
      option.series[0].data = aryjsyl;   
      option.series[1].data = arychyl; 
      option.series[2].data = ary1; 
      option.series[3].data = ary2; 
      myChart10.setOption(option);  
      
      
      var arygy = new Array();//
      var aryzy = new Array();//
      var arydy = new Array();//
      var aryhd = new Array();//
      for (var i = 0 ;i<l;i++) {
      	var a = Math.floor(Math.random()*10+1);
        var b = Math.floor(Math.random()*10+1);
        var c = 23-a-b;
        var d = Math.random();
        arygy.push(a);
        aryzy.push(a);
        arydy.push(c);
        aryhd.push(d);
      }


      
      getDateArry(l);
      var option2 = myChart11.getOption();
      option2.series[0].data = arygy;   
      option2.series[1].data = aryzy; 
      option2.series[2].data = arydy; 
      option2.series[3].data = aryhd; 
      myChart11.setOption(option2);  
}



//获取半个月的日期数组
function p(s) {
    return s < 10 ? '0' + s: s;
}

function getDateArry(l) {
	var datenow = new Date();
    var currentYear=datenow.getFullYear();
     

    var datearry = new Array();
    for (var i = 0;i<l;i++) {
    	var datelast = new Date(datenow.getTime() - 24*60*60*1000*i);
    	var currentMonth=datelast.getMonth()+1; 
    	var currentDate = datelast.getDate();
        var current = currentMonth+"-"+p(currentDate);
        datearry[i] = current;
    }
    datearry.reverse();
    return datearry;
}


var myChart10 = echarts.init(document.getElementById('model10'), 'macarons');
var myChart11 = echarts.init(document.getElementById('model11'), 'macarons');

option10 = {
    title: {
        text: ''
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data:['进水压力','出水压力','1#水箱液位','2#水箱液位'],
        show:false
    },
    
    grid: {
        left: '1%',
        right: '1%',
        bottom: '0%',
        containLabel: true
    },
    toolbox: {
    	show:false
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['','','','',''],
        show:false
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: ''
        },
        axisTick:{
        	show:false
    	},
    	splitLine:{ 
    		lineStyle: {
		        color: '#13232b'
		    }
        },
    },
    series: [
        {
            name:'进水压力',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#192a5b'
					}
            	}
            },
            data:[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,]
        },
        {
            name:'出水压力',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#13fde0'
					}
            	}
            },
            
            data:[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,]
        },
        {
            name:'1#水箱液位',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#c2962c'
					}
            	}
            },
            data:[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,]
        },
        {
            name:'2#水箱液位',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#1fcd4f'
					}
            	}
            },
            data:[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,]
        },

    ]
};
option11 = {
     tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            crossStyle: {
                color: '#999'
            }
        }
    },
    toolbox: {
        feature: {
            dataView: {show: true, readOnly: false},
            magicType: {show: true, type: ['line', 'bar']},
            restore: {show: true},
            saveAsImage: {show: true}
        },
        show:false
    },
    legend: {
        data:['高压时长','中压时长','低压时长','总耗电量'],
        show:false
    },
    grid: {
        left: '1%',
        right: '1%',
        bottom: '1%',
        containLabel: true
    },
    xAxis : [
        {
            axisPointer: {
                type: 'shadow'
            },
            type : 'category',
            axisLabel:{
            	textStyle:{
            		color:'#ffffff'
            	}
            },
            data : getDateArry(),
            show:false
        }
    ],
    yAxis : [
        {
            type : 'value',
            axisLabel: {
                formatter: ''
            },
            axisTick:{
	        	show:false
	    	},
            splitLine:{ 
    			lineStyle: {
			        color: '#13232b'
			    }
	        },
	        min: 0,
            max: 5,
            interval: 2,

        },
        {
            type: 'value',
            name: '',
            min: 0,
            max: 24,
            interval: 5,
            axisLabel: {
                formatter: ''
            },
            show:false
        }
        
    ],
    series : [

        {
            name:'高压时长',
            type:'bar',
            stack: '时长',
            itemStyle: {
                normal: {
                    color:'#13a0e9'
                }
            },
            data:[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]
        },
        {
            name:'中压时长',
            type:'bar',
            stack: '时长',
            itemStyle: {
                normal: {
                    color:'#fff109'
                }
            },
            data:[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]
        },
        {
            name:'低压时长',
            type:'bar',
            stack: '时长',
            itemStyle: {
                normal: {
                    color:'#a7d66d'
                }
            },
            data:[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]
        },
        {
            name:'总耗电量',
            type:'line',
            yAxisIndex: 1,
            smooth:true,
            symbol:'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#d8834c'
					}
            	}
            },
            data:[0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,]
        }
    ]
};

myChart10.setOption(option10);
myChart11.setOption(option11);
$('#query').click(function () {
    DASearch()
})
})